import java.util.Scanner;
public class Main{
    public static void main(String[] args)
    {
        Scanner scaner = new Scanner(System.in);
        while(scaner.hasNextInt())
        {
            int num = scaner.nextInt();
            int data;
            int aNum = 0;
            int mod;
            while((num / 10) != 0)
            {
                data = num;
                aNum = 0;
                while(data!=0)
                {
                    mod = data%10;
                    aNum += mod;
                    data /= 10;
                }
                num = aNum;
            }
            System.out.println(aNum);
        }
    }
}